package cn.neo.hhmq.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;

/**
 * hh message model
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Message<T> {

//    private String topic;

    private Long id;

    // 消息体
    private T body;

    // 消息头
    private Map<String, String> headers = new HashMap<>(); // 系统属性
    // 消息属性

//    private Map<String, String> properties; // 业务属性

    static AtomicLong idgen = new AtomicLong(0);

    public static  long getId(){
        return idgen.getAndIncrement();
    }

    public static Message create(String body, Map<String, String> headers) {
        return new Message<>(getId(), body, headers);
    }

}
